﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Model;
using BLL;
using System.Data.SqlClient;
namespace UI
{
    public partial class FrmHuiyuanguanli : Form
    {
        public FrmHuiyuanguanli()
        {
            InitializeComponent();
        }
        
        private void btnchaxunhuiyuan_Click(object sender, EventArgs e)
        {
            Model_Vips.VipID = this.txtbianhao.Text;
            Model_Vips.VipName = this.txtxingming.Text;
            SqlDataReader dr = BLLCHAallhy.BLLchahyBYid();
            this.listView1.Items.Clear();
            while (dr.Read())
            {
                string VipID = dr["VipID"].ToString();
                string VipName = dr["VipName"].ToString();
                string VipSex = dr["VipSex"].ToString();
                string VGName = dr["VGName"].ToString();
                string VGDiscount = dr["VGDiscount"].ToString();
                string VipTel = dr["VipTel"].ToString();
                string VipStartDate = dr["VipStartDate"].ToString();
                string VipEndDate = dr["VipEndDate"].ToString();
                ListViewItem li = new ListViewItem(VipID);
                li.SubItems.Add(VipName);
                li.SubItems.Add(VipSex);
                li.SubItems.Add(VGName);
                li.SubItems.Add(VGDiscount);
                li.SubItems.Add(VipTel);
                li.SubItems.Add(VipStartDate);
                li.SubItems.Add(VipEndDate);
                this.listView1.Items.Add(li);
            }
            dr.Close();
        }

        private void FrmHuiyuanguanli_Load(object sender, EventArgs e)
        {
            SqlDataReader dr = BLLCHAallhy.BLLchahuiyuan();
            while (dr.Read())
            {
                string VipID = dr["VipID"].ToString();
                string VipName = dr["VipName"].ToString();
                string VipSex = dr["VipSex"].ToString();
                string VGName = dr["VGName"].ToString();
                string VGDiscount = dr["VGDiscount"].ToString();
                string VipTel = dr["VipTel"].ToString();
                string VipStartDate = dr["VipStartDate"].ToString();
                string VipEndDate = dr["VipEndDate"].ToString();
                ListViewItem li = new ListViewItem(VipID);
                li.SubItems.Add(VipName);
                li.SubItems.Add(VipSex);
                li.SubItems.Add(VGName);
                li.SubItems.Add(VGDiscount);
                li.SubItems.Add(VipTel);
                li.SubItems.Add(VipStartDate);
                li.SubItems.Add(VipEndDate);
                this.listView1.Items.Add(li);
            }
            dr.Close();
        }



        private void 添加会员ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            Frm添加会员 f = new Frm添加会员();
            f.Show();
            this.Close();
        }

        private void 删除会员ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count != 1)
            {
                MessageBox.Show("请选中一项");
                return;
            }
            Model_Vips.VipID = listView1.SelectedItems[0].SubItems[0].Text;
          DialogResult da=  MessageBox.Show("确认要删除吗？","温馨提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
            if(da.ToString()=="Yes"){
                int a = BLLCHAallhy.SCvip();
                if (a > 0)
                {
                    MessageBox.Show("删除成功");
                    SqlDataReader dr = BLLCHAallhy.BLLchahuiyuan();
                    this.listView1.Items.Clear();
                    while (dr.Read())
                    {
                        string VipID = dr["VipID"].ToString();
                        string VipName = dr["VipName"].ToString();
                        string VipSex = dr["VipSex"].ToString();
                        string VGName = dr["VGName"].ToString();
                        string VGDiscount = dr["VGDiscount"].ToString();
                        string VipTel = dr["VipTel"].ToString();
                        string VipStartDate = dr["VipStartDate"].ToString();
                        string VipEndDate = dr["VipEndDate"].ToString();
                        ListViewItem li = new ListViewItem(VipID);
                        li.SubItems.Add(VipName);
                        li.SubItems.Add(VipSex);
                        li.SubItems.Add(VGName);
                        li.SubItems.Add(VGDiscount);
                        li.SubItems.Add(VipTel);
                        li.SubItems.Add(VipStartDate);
                        li.SubItems.Add(VipEndDate);
                        this.listView1.Items.Add(li);
                    }
                    dr.Close();
                }
                else { 
                }
            }
        
        }

        private void 修改会员ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count != 1)
            {
                MessageBox.Show("请选中一项");
                return;
            }
            Model_Vips.VipID = this.listView1.SelectedItems[0].SubItems[0].Text;
            Model_Vips.GradeID = this.listView1.SelectedItems[0].SubItems[3].Text; 
            Model_Vips.VipName = "";
            Frm修改会员 f = new Frm修改会员();
            f.Show();
            this.Close();
        }
//查看会员消费记录
        private void 查看消费记录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count !=1)
            {
                MessageBox.Show("请选中一项");
                return;
            }
           Model_Vips.VipID= this.listView1.SelectedItems[0].SubItems[0].Text;
           SqlDataReader dr = BLLCHAallhy.CKvipXF();
           this.listView2.Items.Clear();
            while(dr.Read()){
                string CBID = dr["CBID"].ToString();
                string ProductName = dr["ProductName"].ToString();
                string CDAmount = dr["CDAmount"].ToString();
                string ProductPrice = dr["ProductPrice"].ToString();
                string CDMoney = dr["CDMoney"].ToString();
                string CDDate = dr["CDDate"].ToString();

                ListViewItem li = new ListViewItem(CBID);
                li.SubItems.Add(ProductName);
                li.SubItems.Add(CDAmount);
                li.SubItems.Add(ProductPrice);
                li.SubItems.Add(CDMoney);
                li.SubItems.Add(CDDate);
                this.listView2.Items.Add(li);
            
            }
            dr.Close();
        }

       
    }
}
